<?php $this->load->view('common/header'); ?>
<?php $this->load->view('common/menu'); ?>
<style>
    #wrap{
        display: none;
    }
    .page{display:block;overflow:hidden;margin:40px auto 0;text-align:center;}
    .page li{display:inline-block;vertical-align:top;}
    .page a{display:inline-block;margin-left:5px;vertical-align:top;padding:0 16px;height:40px;text-align:center;line-height:40px;border:#e4e4e4 1px solid;border-radius:3px;font-size:14px;}
    .page a:hover{background-color:#223fd5;border:#223fd5 1px solid;color:#fff;}
    .page li.active span{background-color:#223fd5;border:#223fd5 1px solid;margin-left:5px;vertical-align:top;padding:0 16px;height:40px;text-align:center;line-height:40px;color:#fff;border-radius:3px;font-size:14px;}
    .page span{display:inline-block;margin-left:5px;line-height:32px;vertical-align:top;}
</style>
    <script>
        (function ($) {
            $.extend({
                UrlGetParams: function (m) {
                    var sValue = location.search.match(new RegExp("[\?\&]" + m + "=([^\&]*)(\&?)", "i"));
                    return sValue ? sValue[1] : sValue;
                },
                UrlUpdateParams: function (url, name, value) {
                    var r = url;
                    if (r != null && r != 'undefined' && r != "") {
                        value = encodeURIComponent(value);
                        var reg = new RegExp("(^|)" + name + "=([^&]*)(|$)");
                        var tmp = name + "=" + value;
                        if (url.match(reg) != null) {
                            r = url.replace(eval(reg), tmp);
                        }
                        else {
                            if (url.match("[\?]")) {
                                r = url + "&" + tmp;
                            } else {
                                r = url + "?" + tmp;
                            }
                        }
                    }
                    return r;
                },
                UrlDelParams: function (name) {
                    var loca = window.location;
                    var baseUrl = loca.origin + loca.pathname + "?";
                    var query = loca.search.substr(1);
                    if (query.indexOf(name) > -1) {
                        var obj = {}
                        var arr = query.split("&");
                        for (var i = 0; i < arr.length; i++) {
                            arr[i] = arr[i].split("=");
                            obj[arr[i][0]] = arr[i][1];
                        }
                        ;
                        delete obj[name];
                        var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
                        return url
                    }

                    return window.location.href;
                }
            });
        })(jQuery);

        function listSearch(key, value) {
            var url = $.UrlDelParams("per_page");
            var url = $.UrlUpdateParams(url, key, value);
            console.log(url);
            window.location.href = url;
        }



        // 状态
        function statusBox(status) {
            listSearch('status', status);
        }

        function orderBox(val) {
            listSearch('order', val);
        }

        $(function () {
            $("#search_by").click(function () {

                var keywords = $("#keywords").val();
                listSearch('keyword', keywords);
            });
        });
    </script>
<div class="proper">
    <div class="press_list">
    	<div class="title">
        	<dl>
            	<dt>
                	<span>排序方式</span>
                	<select onchange="orderBox(this.options[this.options.selectedIndex].value)">
                    	<option value="create_time-desc">最近的</option>
                    	<option value="price-asc">租金（从低到高）</option>
                    	<option value="price-desc">租金（从高到低）</option>
                        <option value="create_time-asc">创建日期最早</option>
                    </select>
                </dt>
                <dd>
                    <div class="search">
                        <span><input id="keywords" placeholder="搜索城市，州，邮政编码或地址"></span>
                        <a href="javascript:;" id="search_by">搜索</a>
                    </div>
                </dd>
            </dl>
        </div>
        <div class="wuye_list">
        	<ul>
            <?php if ($products) : ?>
                <?php foreach ($products as $key => $val) : ?>
            	<li>
                	<div class="wuye_box">
                    	<a href="<?php echo "/press_show/" . $val['id'] . ".html"; ?>" class="pic">
                            <img style="width: 255px;height: 120px;" src="<?php echo $val['img'] ?? ""; ?>">
                        </a>
                        <span class="name">
                        	<h1>
                            	<span>
                                	<p>出租</p>
                                    <em>$ <?php echo $val['price']; ?></em>
                                </span>
                            	<span>
                                	<p>床/浴室</p>
                                    <em><?php echo $val['area']; ?></em>
                                </span>
                            	<span>
                                	<p>可用的</p>
                                    <?php if( $val['sell'] == 2){ ?>
                                        <em>现在</em>
                                    <?php }else{ ?>
                                        <em>无</em>
                                    <?php  } ?>
                                </span>
                            </h1>
                        	<a href="press_show.html" class="bt"><?php echo $val['title']; ?></a>
                            <p>2431 S.Christinaa Ave-Unit 2R，Chicago，IL 60623</p>
                            <p><?php echo $val['describe']; ?></p>
                        </span>
                    </div>
                </li>
                <?php endforeach; ?>
            <?php endif; ?>
            </ul>
        </div>
        <div class="page">
            <ul><?php echo $pagination; ?></ul>
        </div>
    </div>
</div>

<?php $this->load->view('common/footer'); ?>